<?php
require_once('includes/config.php');
include('includes/sc-includes.php');

$pagetitle = Profile;
?>
<?php
$query_profile = "SELECT * FROM users";
$row_profile = $sdb->select('users', $query_profile);
$totalRows_profile = count($row_profile);

if ($_POST['email'])
{
	$password = $row_profile[0]['Attributes']['user_password'];

	if ($_POST['password'])
	{
		$password = $_POST['password'];
	}

	$email = trim($_POST['email']);
	$password = trim($password);
	$home = trim($_POST['home']);

	$attributes =  array("user_email" 	 => array("value" => $email, "replace" => "true"),
	  					 "user_password" => array("value" => $password, "replace" => "true"),
	  					 "user_home" 	 => array("value" => $home, "replace" => "true"));

	$sdb->putAttributes('users', $row_profile[0]['Name'], $attributes);

	set_msg('Profile Updated');
	$_SESSION['user'] = $_POST['email'];
	header('Location: profile.php'); die;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Update Profile</title>
<script src="includes/lib/prototype.js" type="text/javascript"></script>
<script src="includes/src/effects.js" type="text/javascript"></script>
<script src="includes/validation.js" type="text/javascript"></script>
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<link href="includes/simplecustomer.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include('includes/header.php'); ?>
<div class="container">
  <div class="leftcolumn">
    <h2>Profile</h2>
    <span class="notices" style="display:<?php echo $dis; ?>">
    <?php display_msg(); ?>
    </span>
    <form id="form1" name="form1" method="post" action="">
      <p>Email
        <br />
        <input name="email" type="text" id="email" value="<?php echo $row_profile[0]['Attributes']['user_email']; ?>" class="required validate-email" size="35" />
      </p>
      <p><br />
        Password (leave blank to keep current password) <br />
        <input name="password" type="password" id="password" />
          <br />
      </p>
      <p>Home Page<br />
        <input name="home" type="radio" value="index.php" <?php if ($row_profile[0]['Attributes']['user_home']=="index.php") { ?>checked="checked"<?php } ?> />
          Dashboard
      </p>
      <p>
        <input name="home" type="radio" value="contacts.php" <?php if ($row_profile[0]['Attributes']['user_home']=="contacts.php") { ?>checked="checked"<?php } ?> />
      Contacts</p>
      <p>
        <input name="Submit2" type="submit" id="Submit2" value="Update" />
        </p>
    </form>

    <p>&nbsp;</p>
  </div>
  <?php include('includes/right-column.php'); ?>
  <br clear="all" />
</div>

<?php include('includes/footer.php'); ?>

</body>
</html>
